package com.ming.easyDevelop.service.impl;

import com.ming.easyDevelop.mappers.UsersMapper;
import com.ming.easyDevelop.entity.po.Users;
import com.ming.easyDevelop.entity.query.UsersQuery;
import java.util.List;

import com.ming.easyDevelop.utils.Interface.LoggerModule;
import com.ming.easyDevelop.utils.annotation.Log;
import org.springframework.stereotype.Service;
import com.ming.easyDevelop.service.UsersService;
import com.ming.easyDevelop.entity.vo.PaginationResVo;
import com.ming.easyDevelop.entity.baseEnum.PageSize;
import com.ming.easyDevelop.entity.query.base.SimplePage;
@Service("usersService")
public class UsersServiceImpl implements UsersService {

	private final UsersMapper<Users, UsersQuery> usersMapper;

	public UsersServiceImpl(UsersMapper usersMapper){
		this.usersMapper = usersMapper;
	}
	/**
	 * 根据条件查询列表
	 */
	@Override
	@Log
	public List<Users> findListByParam(UsersQuery query){
		return this.usersMapper.selectList(query);
	}

	/**
	 * 根据条件查询数量
	 */
	@Override
	public Long findCountByParam(UsersQuery query){
		return this.usersMapper.selectCount(query);
	}

	/**
	 * 根据条件分页查询列表
	 */
	@Override
	public PaginationResVo<Users> findListByPage(UsersQuery query){
		Long count = this.findCountByParam(query);
		int pageSize = query.getPageSize() == null ? PageSize.SIZE20.getSize() : query.getPageSize();
		SimplePage simplePage = new SimplePage(query.getPageNo(), pageSize, Math.toIntExact(count));
		List<Users> res = this.findListByParam(query);
		return new PaginationResVo<Users>(query.getSimplePage().getPageNo(), query.getSimplePage().getPageSize(), query.getSimplePage().getCountTotal(), query.getSimplePage().getPageTotal(), res);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Long addBatch(List<Users> list){
		return this.usersMapper.insertBatch(list);
	}

	/**
	 * 新增
	 */
	@Override
	public Long add(Users bean){
		return this.usersMapper.insert(bean);
	}

	/**
	 * 新增
	 */
	@Override
	public Long addOrUpdate(Users bean){
		return this.usersMapper.insertOrUpdate(bean);
	}

	/**
	 * 新增
	 */
	@Override
	public Long addOrUpdateBatch(List<Users> list){
		return this.usersMapper.insertOrUpdateBatch(list);
	}

	/**
	 * 根据UserID查询
	 */
	@Override
	public Users getByUserID(Integer userID){
		return this.usersMapper.selectByUserID(userID);
	}

	/**
	 * 根据UserID更新
	 */
	@Override
	public Long updateByUserID(Users bean, Integer userID){
		return this.usersMapper.updateByUserID(bean,userID);
	}

	/**
	 * 根据UserID删除
	 */
	@Override
	public Long deleteByUserID(Integer userID){
		return this.usersMapper.deleteByUserID(userID);
	}

	/**
	 * 根据Username查询
	 */
	@Override
	public Users getByUsername(String username){
		return this.usersMapper.selectByUsername(username);
	}

	/**
	 * 根据Username更新
	 */
	@Override
	public Long updateByUsername(Users bean, String username){
		return this.usersMapper.updateByUsername(bean,username);
	}

	/**
	 * 根据Username删除
	 */
	@Override
	public Long deleteByUsername(String username){
		return this.usersMapper.deleteByUsername(username);
	}

	/**
	 * 根据Email查询
	 */
	@Override
	public Users getByEmail(String email){
		return this.usersMapper.selectByEmail(email);
	}

	/**
	 * 根据Email更新
	 */
	@Override
	public Long updateByEmail(Users bean, String email){
		return this.usersMapper.updateByEmail(bean,email);
	}

	/**
	 * 根据Email删除
	 */
	@Override
	public Long deleteByEmail(String email){
		return this.usersMapper.deleteByEmail(email);
	}

	enum BaseLogModule implements LoggerModule {
		APPLICATION("Application", "Main", "Application related logs"),
		DATABASE("Database", "DB", "Database operation logs"),
		CHILDREN("Children", "ChildTask", "Starting child task");

		private final String moduleMsg;
		private final String subModule;
		private final String subModuleMsg;

		BaseLogModule(String moduleMsg, String subModule, String subModuleMsg) {
			this.moduleMsg = moduleMsg;
			this.subModule = subModule;
			this.subModuleMsg = subModuleMsg;
		}

		public String getModuleMsg() {
			return moduleMsg;
		}

		public String getSubModule() {
			return subModule;
		}

		public String getSubModuleMsg() {
			return subModuleMsg;
		}
	}


}
